import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

export class GameData{
    private static readonly BEST_SCORE: string = 'best_score'
    private static _score: number = 0;

    public static addScore(count: number=1){
        this._score += count
    }

    public static getScore(){
        return this._score
    }

    public static getBestScore(){
        let score = localStorage.getItem(this.BEST_SCORE)
        return score ? parseInt(score) : 0
    }

    public static saveBestScore(){
        let bestScore = this.getBestScore()
        if(bestScore < this._score){
            localStorage.setItem(this.BEST_SCORE, this._score.toString())
        }
        this._score = 0
    }
}

